package com.hrsoft.edi.stub;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.hrsoft.edi.stub.request.TransferorderCreateRequest;
import com.qimen.api.DefaultQimenClient;
import com.qimen.api.QimenClient;
import com.qimen.api.response.TransferorderCreateResponse;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName StockOutCreateTest
 * @Author huyka
 * @Date 2019/5/30 16:58
 * @Description
 */
@Slf4j
public class TransferOrderCreateTest {
    private static final String URL = "http://172.172.172.97:8765/api/edi/qimen/service/";

    private static final String APP_KEY = "20191220";

    private static final String SECRET = "20191220";

    public static void create()
            throws ApiException
    {
        QimenClient client = new DefaultQimenClient(URL, APP_KEY, SECRET);
        TransferorderCreateRequest createRequest = new TransferorderCreateRequest();
        createRequest.setCustomerId("manager");
        createRequest.setVersion("2.0");
        TransferorderCreateRequest.TransferOrder transferOrder = new TransferorderCreateRequest.TransferOrder();
        transferOrder.setErpOrderCode("DB" + RandomUtil.randomNumbers(15));
        transferOrder.setOwnerCode("MYHZ");
        transferOrder.setFromStoreCode("LYY");
        transferOrder.setToStoreCode("XYY");
        transferOrder.setExpectStartTime(DateUtil.formatDateTime(new Date()));
        createRequest.setTransferOrder(transferOrder);

        TransferorderCreateRequest.TransferItem transferItem = new TransferorderCreateRequest.TransferItem();
        transferItem.setScItemCode("1207");
        transferItem.setCount("50");
        transferItem.setInventoryType(1L);
        List<TransferorderCreateRequest.TransferItem> transferItemList = new ArrayList<>();
        transferItemList.add(transferItem);
        createRequest.setTransferItems(transferItemList);

        long time1 = System.currentTimeMillis();
        TransferorderCreateResponse response = client.execute(createRequest);
        long time2 = System.currentTimeMillis();
        log.info(response.getCode() + response.getFlag() + response.getMessage() + response.getTransferExecuteInfo().getTransferOrderCode() +" cost:"+ (time2-time1));
    }

    public static void main(String[] args)
            throws ApiException
    {
//        for (int i = 0; i < 50; i++)
//        {
//            create();
//        }
        create();
    }
}
